import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import approvals from '@/router/modules/approvals.js'
import attendances from '@/router/modules/attendances.js'
import departments from '@/router/modules/departments.js'
import employees from '@/router/modules/employees.js'
import settings from '@/router/modules/settings.js'
import salarys from '@/router/modules/salarys.js'
import social_security from '@/router/modules/social_security.js'
import permissions from '@/router/modules/permissions.js'

// 动态路由
export const asyncRoutes = [
  departments, employees, settings, permissions, salarys, social_security, attendances, approvals
]

// 静态路由：404  login
export const constantRoutes = [
  { path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard'),
      meta: { title: '首页', icon: 'dashboard' }
    }] },
  { path: '/import',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/import')
    }] },
  { path: '/detail',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/employees/detail')
    }] },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
